﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LibraryO2S;
using System.Data;
public partial class Administrator_ReportEdit : System.Web.UI.Page
{


    BizReport report = new BizReport();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }
    }
    public int REPORTID
    {
        get
        {
            return
          int.Parse(Request.QueryString["REPORTID"].ToString());
        }

    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            string modifiedBy = Session["USERNAME"].ToString();

            report.Update(REPORTID, txtTitle.Text, txtDescription.Text, txtURL.Text, DateTime.Parse(txtStartDate.Text), DateTime.Parse(txtEndDate.Text), CreatedDate, CreatedBy, DateTime.Now, modifiedBy);
            divMessage.InnerHtml = O2S_Message.Success("Hệ thống", "Thực hiện thành công");
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = O2S_Message.Error("Hệ thống", "Phát hiện lỗi" + ex.Message);
        }

    }
    public void LoadData()
    {
        DataTable db = report.SearchById(REPORTID);
        txtTitle.Text = db.Rows[0]["TITLE"].ToString();
        txtURL.Text = db.Rows[0]["LINKURL"].ToString();
        txtDescription.Text = db.Rows[0]["DESCRIPTION"].ToString();
        txtStartDate.Text = db.Rows[0]["STARTDATE"].ToString();
        txtEndDate.Text = db.Rows[0]["ENDDATE"].ToString();
    }
    public DateTime CreatedDate
    {
        get
        {
            return DateTime.Parse(report.SearchById(REPORTID).Rows[0]["CREATEDDATE"].ToString());
        }
    }
    public string CreatedBy
    {
        get
        {
            return report.SearchById(REPORTID).Rows[0]["CREATEDBY"].ToString();
        }
    }
}